package com.ruoyi.web.controller.teacher;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.SysCourse;
import com.ruoyi.teacher.service.ISysCourseService;
import com.ruoyi.teacher.service.ISysProfessionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * sysCourseController
 * @author ruoyi
 * @date 2022-01-13
 */
@Controller
@RequestMapping("/teacher/course")
public class SysCourseController extends BaseController
{
    private String prefix = "teacher/course";

    @Autowired
    private ISysCourseService sysCourseService;
    @Autowired
    private ISysProfessionService sysProfessionService;

    @RequiresPermissions("teacher:course:view")
    @GetMapping()
    public String course()
    {
        return prefix + "/course";
    }

    /**
     * 查询sysCourse列表
     */
    @RequiresPermissions("teacher:course:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCourse sysCourse)
    {
        startPage();
        List<SysCourse> list = sysCourseService.selectSysCourseList(sysCourse);
        return getDataTable(list);
    }

    /**
     * 新增sysCourse
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("professions", sysProfessionService.selectProfessionAll());
        return prefix + "/add";
    }

    /**
     * 新增保存sysCourse
     */
    @RequiresPermissions("teacher:course:add")
    @Log(title = "sysCourse", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCourse sysCourse)
    {
        sysCourse.setCreateBy(getLoginName());
        return toAjax(sysCourseService.insertSysCourse(sysCourse));
    }

    /**
     * 修改sysCourse
     */
    @RequiresPermissions("teacher:course:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCourse sysCourse = sysCourseService.selectSysCourseById(id);
        mmap.put("professions", sysProfessionService.selectProfessionsByProfessionId(sysCourse.getProfessionId()));
        mmap.put("sysCourse", sysCourse);
        return prefix + "/edit";
    }

    /**
     * 修改保存sysCourse
     */
    @RequiresPermissions("teacher:course:edit")
    @Log(title = "sysCourse", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCourse sysCourse)
    {
        sysCourse.setUpdateBy(getLoginName());
        return toAjax(sysCourseService.updateSysCourse(sysCourse));
    }

    /**
     * 删除sysCourse
     */
    @RequiresPermissions("teacher:course:remove")
    @Log(title = "sysCourse", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCourseService.deleteSysCourseByIds(ids));
    }


/*
    */
/**
     * 校验用户名
     *//*

    @PostMapping("/checkCardUnique")
    @ResponseBody
    public String checkCardUnique(SysCourse sysCourse)
    {
        return sysCourseService.checkCardUnique(sysCourse.getCard());
    }

    @PostMapping("/checkCourseIdUnique")
    @ResponseBody
    public String checkCourseIdUnique(SysCourse sysCourse)
    {
        return sysCourseService.checkCourseIdUnique(sysCourse.getCourseId());
    }
*/


}
